Skip to content

Commit b20e834

Browse files
Randell Jesupmoz-wptsync-bot
Randell Jesup
authored andcommitted
Don't allow overwrite of files/directories using move()
Depends on D150663 Differential Revision: https://phabricator.services.mozilla.com/D157643 bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1791384 gecko-commit: e0355ac9047673122eb9bc6876a06d4c5ddcd79d gecko-reviewers: dom-storage-reviewers, jari
1 parent 8b48818 commit b20e834

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

fs/script-tests/FileSystemFileHandle-move.js

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,11 @@ directory_test(async (t, root) => {
8686
await promise_rejects_dom(
8787
t, 'NoModificationAllowedError', handle.move('file-after'));
8888

89-
// Can move handle once the writable is closed.
89+
// Can't move handle once the writable is closed.
9090
await stream.close();
91-
await handle.move('file-after');
92-
assert_array_equals(await getSortedDirectoryEntries(root), ['file-after']);
91+
await promise_rejects_dom(
92+
t, 'NoModificationAllowedError', handle.move('file-after'));
93+
assert_array_equals(await getSortedDirectoryEntries(root), ['file-before']);
9394
}, 'move(name) while the destination file has an open writable fails');
9495

9596

@@ -308,15 +309,11 @@ directory_test(async (t, root) => {
308309
// Assert the file is still in the source directory.
309310
assert_array_equals(await getSortedDirectoryEntries(dir_src), ['file']);
310311

311-
// Can move handle once the writable is closed.
312+
// Can't move handle once the writable is closed.
312313
await stream.close();
313-
await file.move(dir_dest);
314-
assert_array_equals(
315-
await getSortedDirectoryEntries(root), ['dir-dest/', 'dir-src/']);
316-
assert_array_equals(await getSortedDirectoryEntries(dir_src), []);
317-
assert_array_equals(await getSortedDirectoryEntries(dir_dest), ['file']);
318-
assert_equals(await getFileContents(file), 'abc');
319-
assert_equals(await getFileSize(file), 3);
314+
await promise_rejects_dom(
315+
t, 'NoModificationAllowedError', file.move(dir_dest));
316+
assert_array_equals(await getSortedDirectoryEntries(dir_src), ['file']);
320317
}, 'move(dir) while the destination file has an open writable fails');
321318

322319
directory_test(async (t, root) => {
@@ -336,13 +333,12 @@ directory_test(async (t, root) => {
336333
// Assert the file is still in the source directory.
337334
assert_array_equals(await getSortedDirectoryEntries(dir_src), ['file-src']);
338335

339-
// Can move handle once the writable is closed.
336+
// Can't move handle once the writable is closed.
340337
await stream.close();
341-
await file.move(dir_dest, 'file-dest');
342-
assert_array_equals(
343-
await getSortedDirectoryEntries(root), ['dir-dest/', 'dir-src/']);
344-
assert_array_equals(await getSortedDirectoryEntries(dir_src), []);
345-
assert_array_equals(await getSortedDirectoryEntries(dir_dest), ['file-dest']);
338+
await promise_rejects_dom(
339+
t, 'NoModificationAllowedError', file.move(dir_dest, 'file-dest'));
340+
// Assert the file is still in the source directory.
341+
assert_array_equals(await getSortedDirectoryEntries(dir_src), ['file-src']);
346342
assert_equals(await getFileContents(file), 'abc');
347343
assert_equals(await getFileSize(file), 3);
348344
}, 'move(dir, name) while the destination file has an open writable fails');

0 commit comments

Comments
 (0)